#!/usr/bin/env python
# -*- coding:utf-8 -*-
import redis

class RedisHelper():
    def __init__(self):
        self.__conn=redis.Redis(host='192.168.136.8')   #连接实例化
        #Redis<ConnectionPool<Connection<host=192.168.136.8,port=6379,db=0>>>
        self.chan_pub='fm104.5' #生产者通道名称
        self.chan_sub='fm104.5' #消费者通道名称

    def publish(self,msg):
        self.__conn.publish(self.chan_pub,msg)  #对象方法publish
        return True

    def subscribe(self):
        sub=self.__conn.pubsub()    #pubsub方法调用PubSub类，创建一个订阅对象
        sub.subscribe(self.chan_sub)    #订阅哪个频道
        sub.parse_response()    #解析从redis通道的响应，获取msg
        return sub

